package domain.weapon;

import static java.awt.geom.Point2D.distanceSq;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Circle;
import components.CircularShape;
import components.Shape;

import domain.components.WormsComponent;
import domain.scenes.MainGameScene;

public class Explosion extends WormsComponent {

	private int power;
	private int diameter;
	private int height;
	
	
	public Explosion(int aPower, int aDiameter, int aHeight, double x, double y) {
		super(aDiameter, aHeight, x, y);
		this.power = aPower;
		this.diameter = aDiameter;
		this.height = aHeight;
		this.setAppearance(new Circle(Color.RED, aDiameter));
	}

	@Override
	protected void defineCollide(WormsComponent gc) {
		gc.collideWithExplosion(this);
	}
	
	@Override
	protected void effectiveUpdate(DeltaState deltaState) {

		//this.collideAll(this.getX(), this.getY());
//		this.getScene().destroyTerrain(this);
	//	this.destroyComponent();
	}

	@Override
	public Shape defineShape() {
		return new CircularShape(this);
	}

	public int getPower() {
		return power;
	}

	public void setPower(int power) {
		this.power = power;
	}

	public double calculateDamage(WormsComponent wc) {
		double dist, dmg ;
		dist = distanceSq(wc.getCenterX(),wc.getCenterY(), this.getCenterX(), this.getCenterY());
		dist = Math.sqrt(dist);
		//dmg = this.getPower() - this.getPower()*dist/this.getDiameter()/2;
		dmg = this.getPower() - dist;
		if (dmg < this.getMinDamage()){
			return this.getMinDamage();
		}
		else{
			return dmg;
		}
	}
	
	public double getMinDamage(){
		return this.getPower()/10;
	}

	public int getDiameter() {
		return diameter;
	}

	public void setDiameter(int diameter) {
		this.diameter = diameter;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void damage(MainGameScene scene) {
		this.setScene(scene);
		this.collideAll(this.getX(), this.getY());
		this.destroyComponent();
	}

	
}
